/**

 @Name：layuiAdmin 主页示例
 @Author：star1029
 @Site：http://www.layui.com/admin/
 @License：GPL-2
    
 */ 
//LAY-duban-table 督办事项          LAY-kpi-table KPI进度    LAY-plan-table 工作计划  LAY-data-table数据看板   LAY-meeting-table会议事项
layui.define(['form','laydate','upload','xmSelect','table'],function(exports){
  var admin = layui.admin;
  var $ = layui.$
	,form = layui.form
	,common = layui.common
	,setter = layui.setter
	,laydate = layui.laydate
	,xmSelect = layui.xmSelect
	,upload = layui.upload
	,table=layui.table;
	var colsArr;
	var colsArr1;
	var colsArr2;
	var colsArr3;
	var colsArr4;
	var tableHead;//表头字段  
	//var tableSearch = {};//全局搜索条件
	var parentJson = {};
    var userid = sessionid;
    var thecount = 0;
    var arrayi = 0;
    var thearray=new Array();

	
//	var cam = document.getElementById("checkallmeeting");
//    cam.href= "http:"+setter.host + "unite_platform/meeting_info_detail/toSelect";
//	var cad = document.getElementById("checkallduban");
//    cad.href= "http:"+setter.host + "unite_platform/meeting_info_detail/toSelect";
	var search = [null,null];
	var aa = {};
	/*aa.conditionField = "checkuserid";
	aa.conditionValue =  userid;
	aa.conditionOption = "like";
	aa.logicalOperator="and";
	search[0] = aa;*/
	var bb = {};
/*	bb.conditionField = "a.flag";
	bb.conditionValue =  10;
	bb.conditionOption = "=";
	bb.logicalOperator="and";
	search[1] = bb;*/
	colsArr = [																//督办事项
		{field: '', title: '序号',align:'center' ,type: 'numbers' },
		{field: 'mno', title: '会议编号',align:'center',sort: true , hide:true },
		{field: 'ino', title: '事项编号',align:'center',sort: true , hide:true },
		{field: 'meetingitem', title: '会议事项',align:'center',sort: true ,width:100 },
		{field: 'replycontent', title: '回复内容',align:'center',sort: true,hide:true   },
		{field: 'commitcontent', title: '需要提供内容',align:'center',sort: true, hide:true  },
		{field: 'flag', title: '状态',align:'center',sort: true ,templet: function(d){
			  if(d.flag==9){return '已完成'}else if(d.flag==10){return '未完成'}else{return '已取消'}
		        
		      } 
		},
		{field: 'dutyuserid', title: '责任人',align:'center',sort: true  , hide:true },
		{field: 'dutyuser', title: '责任人姓名',align:'center',sort: true },
		{field: 'completedate', title: '完成时间',align:'center',sort: true ,width: 205,hide:true },
		{field: 'replydate', title: '完成时间',align:'center',sort: true ,width: 130 }
	];
	colsArr1 = [                                                              //KPI进度
		{field: '', title: '序号',align:'center',sort: true,type: 'numbers'},
		{field: '', title: '内容',align:'center',sort: true  },
		{field: '', title: '完成时间',align:'center',sort: true},
		{field: '', title: '完成进度',align:'center',sort: true  },
	];
	colsArr2 = [                                                              //工作计划
		{field: '', title: '序号',align:'center',sort: true,type: 'numbers'},
		{field: 'content', title: '内容',align:'center',sort: true  },
		{field: 'enddate', title: '预计完成时间',align:'center',sort: true},
		{field: 'jindu', title: '进度',align:'center',sort: true  },
	];
    colsArr3 = [                                                              //数据看板
		{field: '', title: '序号',align:'center',sort: true  },
		{field: '', title: '内容',align:'center',sort: true  },
		{field: '', title: '完成时间',align:'center',sort: true  },
	];
	colsArr4 = [                                                              //会议事项
		{field: '', title: '序号',align:'center',type: 'numbers' },
		{field: 'mno', title: '会议编号',align:'center',sort: true ,width: 125 , hide:true},
		{field: 'ino', title: '事项编号',align:'center',sort: true,width: 110 , hide:true },
		{field: 'meetingitem', title: '会议事项',align:'center' },
		{field: 'decisionuserid', title: '决策人',align:'center',sort: true ,width: 100,hide:true  },
		{field: 'decisionuser', title: '决策人',align:'center',sort: true ,width: 120,hide:true  },
		{field: 'shouldlastdate', title: '预计完成时间',align:'center',width: 160 },
		{field: 'dutyuserid', title: '责任人',align:'center',sort: true  ,width: 100,hide:true},
		{field: 'dutyuser', title: '责任人',align:'center',sort: true  ,width: 120,hide:true},
		{field: 'commitcontent', title: '需要提供内容',align:'center',sort: true ,width: 140,hide:true  },
		{field: 'ischeck', title: '是否需要检视',align:'center',sort: true,width: 140 ,hide:true },
		{field: 'checkuserid', title: '检视人',align:'center',sort: true,width: 100,hide:true  },
		{field: 'checkuser', title: '检视人',align:'center',sort: true ,width: 120 ,hide:true},
		{field: 'money', title: '奖罚',align:'center',sort: true ,width: 100,hide:true },
		{field: 'flag', title: '状态',align:'center',sort: true ,width: 100,hide:true },
		{field: 'flagname', title: '状态',align:'center',sort: true ,width: 100,hide:true },
		{field: 'replycontent', title: '回复内容',align:'center',sort: true,width: 120 ,hide:true  },
		{field: 'completedate', title: '完成时间',align:'center',sort: true ,width: 180  ,hide:true},
		{field: 'img', title: '检视图片',align:'center',sort: true,width: 120,hide:true  },
		{field: 'video', title: '检视视频',align:'center',sort: true,width: 120  ,hide:true},
		{field: 'fujian', title: '检视附件',align:'center',sort: true ,width: 120 ,hide:true},
		{field: 'completedate', title: '完成时间',align:'center',sort: true ,hide:true },
		{field: 'replydate', title: '预计完成时间',align:'center',sort: true ,hide:true },//2021-02-16 03:04:04
		{field: 'operation', title: '倒计时(天)',align:'center',width: 95,templet: function(d){
						var myDate = new Date();
						var days =getDayChaBetween(myDate.getFullYear()+"-"+(myDate.getMonth()+1)+"-"+myDate.getDate(),d.shouldlastdate);
						days = Math.floor(days);
					    if(days>=0){
								    if(days>3){thecount=thecount+1; return days;}
				 					else{thearray[arrayi]=thecount; arrayi = arrayi +1 ;thecount=thecount+1; return days;}
							}
			            else{ 
				            thearray[arrayi]=thecount; 
                            arrayi = arrayi +1 ;
				            thecount=thecount+1;
							return 0;
							}		
		      } 
		},
		{field: 'operation', title: '操作',align:'center',width: 95,toolbar: '#barDemo' },
	];
    layui.each(colsArr,function(inx,val){
		tableHead += val.hasOwnProperty('field')?val.field:'-';
		tableHead += ',';
	 })
	//tableHead是获取表字段
	tableHead = tableHead.substring(tableHead.indexOf(',')+1,tableHead.length-1);
	parentJson.search = search;
	parentJson.headField = tableHead;
	parentJson.sessionid = sessionid;
	//督办事项
	console.log(parentJson);
	table.render({
		elem: '#LAY-duban-table'
		,url:  'http:'+setter.host + 'unite_platform/meeting_info_detail/getduban' 
		,cols: [colsArr]
		//,toolbar: 'true'
		//,defaultToolbar: ['print']
		,method:'post'
		,contentType:'application/json; charset=utf-8'
		,where:parentJson
		,height: '205'
		,text: {
		none: '暂无相关数据' 
		}
		
	});
    tableHead='';//表头字段  
	parentJson = {};


     layui.each(colsArr1,function(inx,val){
		tableHead += val.hasOwnProperty('field')?val.field:'-';
		tableHead += ',';
	 })
	//tableHead是获取表字段
	tableHead = tableHead.substring(tableHead.indexOf(',')+1,tableHead.length-1);
	parentJson.headField = tableHead;
	//KPI进度
	table.render({
		elem: '#LAY-kpi-table'
		,data:[]
		//,url:  'http:'+setter.host + 'unite_platform/meeting_info_detail/getSelectBody' 
		,cols: [colsArr1]
		//,toolbar: 'true'
		//,defaultToolbar: ['print']
		,method:'post'
		,contentType:'application/json; charset=utf-8'
		,where:parentJson
		,height: '345'
		,text: {
		none: '暂无相关数据' 
		}
	});
    tableHead='';//表头字段  
	parentJson = {};
  
    layui.each(colsArr2,function(inx,val){
		tableHead += val.hasOwnProperty('field')?val.field:'-';
		tableHead += ',';
	 })
	//tableHead是获取表字段
	tableHead = tableHead.substring(tableHead.indexOf(',')+1,tableHead.length-1);
	parentJson.headField = tableHead;
	parentJson.sessionid = sessionid;
	//工作计划
	table.render({
		elem: '#LAY-plan-table'
		,url:  'http:'+setter.host + 'unite_platform/work_plan_info/sample_getSelectBody' 
		,cols: [colsArr2]
		,method:'post'
		,contentType:'application/json; charset=utf-8'
		,where:parentJson
		,height: '205'
		,text: {
		none: '暂无相关数据' 
		}
	});
    tableHead='';//表头字段  
	parentJson = {};

  layui.each(colsArr3,function(inx,val){
		tableHead += val.hasOwnProperty('field')?val.field:'-';
		tableHead += ',';
	 })
	//tableHead是获取表字段
	tableHead = tableHead.substring(tableHead.indexOf(',')+1,tableHead.length-1);
	parentJson.headField = tableHead;
	//数据看板
	table.render({
		elem: '#LAY-data-table'
		,data:[]
		//,url:  'http:'+setter.host + 'unite_platform/meeting_info_detail/getSelectBody' 
		,cols: [colsArr3]
		//,toolbar: 'true'
		//,defaultToolbar: ['print']
		,method:'post'
		,contentType:'application/json; charset=utf-8'
		,where:parentJson
		,height: '345'
		,text: {
		none: '暂无相关数据' 
		}
	});
	
	
	
    tableHead='';//表头字段  
	parentJson = {};

	
    layui.each(colsArr4,function(inx,val){
		tableHead += val.hasOwnProperty('field')?val.field:'-';
		tableHead += ',';
	 })
	//tableHead是获取表字段
	tableHead = tableHead.substring(tableHead.indexOf(',')+1,tableHead.length-1);
	/*aa.conditionField = "dutyuserid";
	aa.conditionValue =  userid;
	aa.conditionOption = "like";*/
	search[0] = aa;
	parentJson.search=search;
	parentJson.headField = tableHead;
	parentJson.sessionid = sessionid;
	//会议事项
	table.render({
		elem: '#LAY-meeting-table'
		,url:  'http:'+setter.host + 'unite_platform/meeting_info_detail/sample_getSelectBody' 
		,cols: [colsArr4]
		,method:'post'
		,contentType:'application/json; charset=utf-8'
		,where:parentJson
		,height: '205'
		,text: {
		none: '暂无相关数据' 
		}
		,done:function(res){
			console.log(res.data1);
			document.getElementById('thenumber').innerHTML ='('+res.data1[0].finished+'/'+res.data1[0].unfinished+')';
			for(var i =0;i<thearray.length;i++)
			{Layui_SetDataTableRowColor('huiyishixiang',thearray[i],'#ff0033');}	
			//console.log(thearray);
			}
		});
		table.on('tool(LAY-meeting-table)', function(obj){
			var data = obj.data //获得当前行数据
	             console.log(obj.data.flag);
 					console.log(obj.data.flagname);
				 if(obj.event === 'detail'){
					if(obj.data.flag==12){
						 obj.data.bakUrl = setter.host+'unite_platform/meeting_info_detail/toSelect';
		                 obj.data.jsType = 'edit';
							 layui.common.postUrl(obj.data,setter.host+'unite_platform/meeting_info_detail/huifu');
					}else{
						obj.data.bakUrl = setter.host+'unite_platform/meeting_info_detail/toSelect';
							obj.data.jsType = 'edit';
							layui.common.postUrl(obj.data,setter.host+'unite_platform/meeting_info_detail/tosearchreply');//toSearch
					}
					

	  			 } 

		});
		
  exports('sample', {})
function  getDayChaBetween(date1,date2){
	   var  startDate = Date.parse(date1);
	   var  endDate = Date.parse(date2);
	   var days=(endDate - startDate)/(1*24*60*60*1000);
	   // alert(days);
	   return  days;
	}
	
	
	 function Layui_SetDataTableRowColor(TabDivId,RowIndex, ColorString)
  {
    try
    {
      var div = document.getElementById(TabDivId);
      if(div != null) //找到对象了
      {
        var table_main = div.getElementsByClassName('layui-table-main');  //通过class获取table_main
        if (table_main != null && table_main.length > 0)
        {
          var table = table_main[0].getElementsByClassName('layui-table');  //通过class获取table
          if (table != null && table.length > 0) {
	
            var trs = table[0].querySelectorAll("tr");
            if (trs != null && trs.length > 0) {
	
              trs[RowIndex].style.color = ColorString;
            }
          }
        }
        
      }
    }
    catch(e)
    {
      console.log(e.message);
    }
  }

});